function jcb_make_pdf_from_images(name,maxrows,maxcols)
%%
if nargin<3
    maxcols=2;
end

if nargin<2
    maxrows=2;
end

if nargin<1
    name='';
else
    if ~isempty(name)
        name=[name '_'];
    end
end

papersizemm=[210 297];
masks={'*.png','PNGs';
       '*.jpg;*.jpeg','JPEGs';
       '*.gif','GIFs';
       '*.jpg;*.jpeg;*.png;*.gif','All image files (*.jpg,*.jpeg,*.png,*.gif)';
       '*.*','All files';};
   
[filelist,pathname] = jcb_pick_files(masks,'Select winspec files to plot',true,pwd);

figure(1);
clf;
set(gcf,'PaperPositionMode','manual',...
        'PaperUnits','centimeters',...
        'PaperPosition',[0 0 0.1*papersizemm],...
        'Units','centimeters',...
        'position',[0 0 0.1*papersizemm]);
fontsize=5;
for ii=1:length(filelist)
    subplot(maxrows,...
            min(ceil(length(filelist)/maxrows),maxcols),...
            mod(ii-1,maxrows*maxcols)+1);
    filename=fullfile(pathname,filelist{ii});
    im=imread(filename);
    image(im);
    axis off
    axis image
    
    set(gca,'units','centimeters');
    t=text('units','centimeters',...
           'fontsize',fontsize,...
           'string',strrep(filename,'K:\','\\Ma-fs\shared\Lab4\'),...
           'interpreter','none');
    textent=get(t,'extent');
    axsize=get(gca,'position');
    set(t, 'position',[(axsize(3)-textent(3))/2 -0.1]);
    
    

    if mod(ii,maxrows*maxcols)==0 || ii==length(filelist)
        print('-dpdf',fullfile(pathname,[name 'collection_' num2str(ceil(ii/(maxrows*maxcols)))]));
        clf;
    end
end
close(1);
